#include <stddef.h>

#define bool int

#define true 1
#define false 0

enum STRUCT{
    TABLELIST,
    DATABASECONFIG
}; 
enum Type{FIELD_INT,FIELD_STRING,FIELD_DOUBLE};
enum EXECEUTERROR{
    CONFIG_FILE_OPEN_ERROR,
    CREATE_DATABASE_ERROR,
    DATABASE_NOT_EXIST_ERROR,
    CONFIG_TABLE_CREATE_ERROR,
    FILE_OPEN_ERROR,
    DIRECTORY_OPEN_ERROR};

enum SQLTYPE{
    HELPSQL, EXITSQL,
    CREATEDATABASESQL, SHOWDATABASESSQL, 
    SHOWTABLESSQL,DESCSQL,
    DROPDATABASESQL,DROPTABLESQL,
    SELECTSQL,INSERTSQL,UPDATESQL,DELETESQL
};

enum CMP{
    GT,GE,EQ,LT,LE,NE
};

typedef struct Data{
    union{
        double d;
        int i;
        char * m_string;
    } value;
}DataStruct,* DataStructPoint;


typedef struct CreateField{
    char * name;
    enum Type type;
    int  length;
    struct CreateField * next;
}CreateFieldStruct,* CreateFieldStructPoint;

typedef struct Create{
    char * name;
    CreateFieldStructPoint fileds;
}CreateStruct,*CreateStructPoint;


typedef struct TableList{
    char name[128];
    struct TableList * next;
}TableListStruct,*TableListStructPoint;

typedef struct DatabaseConfig{
    char * configPath;
    char * m_dataPath;
    char * m_instructmentPath;
    int tabLength;
}DatabaseConfigStruct, * DatabaseConfigStructPoint;




char * strpathcat(char * prefix,char * other);

//Get the database config;
void initDatabase();

void _exitDatabase();
void freeGlobalVariable();

//Error handle;
void handleError(enum EXECEUTERROR error,void * data);
//Read table list from database.
TableListStructPoint readTableList();
void freeStruct(enum STRUCT type,void * root);
//Write back table list.
bool writebackTableList(); 

int calTabCnt(int max);
void borderPrint(int cnt);
void contentPrint(char * res,int cnt);

//Sql execution enterance.
void executeSQL(void * syntaxTree,int type);


// help;
void help();
// exit;
//Create database dbname;
void createDatabase(char * dbname);
//Show database;
void showDatabases();

void dropDatabase();

//Show tables;
void showTables();